
local e_util = require "libs/entutil"
local t_util = require "libs/tableutil"
local c_util = require "libs/calcutil"
local screenfunc1,screenfunc2 = {},{}

local ectrl, string_tele
AddClassPostConstruct("widgets/inventorybar",function(self, player)
    local _Rebuild = self.Rebuild
    self.Rebuild = function(...)
        local result = _Rebuild(...)
        if self.ectrl then self.ectrl:Kill() end
        self.ectrl = self:AddChild(require("widgets/hx_equipcontrol")(self, player))
        screenfunc1.ResetPos = {
            value = true,
            fn = function()
                self.ectrl:InitSelfPosition()
            end,
            hover = "恢复默认的位置\n默认的位置是装备栏上面\n不喜欢的话可以拖动改变",
            label = "重置栏位位置",
        }
        screenfunc1.ShowUI = function()
            local isshown = self.ectrl:IsVisible()
            return {
                value = isshown,
                fn = function(btn)
                    self.ectrl:ToHide(isshown)
                    isshown = not isshown
                    btn.img_or:SetTexture("images/shroomcake_moreicons.xml", isshown and "right.tex" or "wrong.tex")
                end,
                hover = "还有个快捷方式:\n右键点击下面的【检查自我】",
                label = "大师栏UI显示",
            }
        end
        ectrl = self.ectrl
        local ins = self.inspectcontrol
        if ins then
            local _OnMouseButton = ins.OnMouseButton
            function ins:OnMouseButton(press, down, ...)
                if press == GLOBAL.MOUSEBUTTON_RIGHT and not down then
                    ectrl:ToHide(ectrl:IsVisible())
                end
                return _OnMouseButton(self, press, down, ...)
            end
        end
        return result
    end
end)

local function EquipmentControl(player)
    local c_mana = require("libs/ctrlmanager")
    local p_util = require("libs/playerutil")
    local inDark = false
    local rg_mode = c_mana:GetAttackRangeMode()
    local cp_mode = c_mana:GetCompatibleMode()
    local not_mv_range = c_mana:GetLeft_not_MV()
    local has_mv_range = c_mana:GetLeft_Has_MV()
    local fight_range = c_mana:GetFightRange()
    local starve_value = c_mana:GetStarveValue()
    local copy_right = c_mana:GetRCMode()
    local double_click = c_mana:GetDBClick()
    screenfunc2 = {}

    local function install_starve()
        return {
            value = true,
            openfn = function(text, btn)
                if text then
                    starve_value = text
                    c_mana:SetStarveValue(starve_value)
                    btn.labeltext:SetString("自动吃饭阈值："..starve_value)
                end
            end,
            fn = function(btn)end,
            hover = "当饥饿值低于此数值时自动吃饭。默认：0",
            label = "自动吃饭阈值："..starve_value,
        }
    end
    table.insert(screenfunc2, install_starve)

    local function install_fight_range()
        return {
            value = true,
            openfn = function(text, btn)
                if text then
                    fight_range = text
                    c_mana:SetFightRange(fight_range)
                    btn.labeltext:SetString("脱战距离："..fight_range)
                end
            end,
            fn = function(btn)end,
            hover = "即使怪物有仇恨，脱离该范围也算脱战。默认：25",
            label = "脱战距离："..fight_range,
        }
    end
    table.insert(screenfunc2, install_fight_range)
    local function install_not_mv()
        return {
            value = true,
            openfn = function(text, btn)
                if text then
                    not_mv_range = text
                    c_mana:SetLeft_not_MV(not_mv_range)
                    btn.labeltext:SetString("抬手距离[关延迟]："..not_mv_range)
                end
            end,
            fn = function(btn)end,
            hover = "关延迟时切换攻击模式的距离\n 该数值默认是1\n 你可以点击按钮修改",
            label = "抬手距离[关延迟]："..not_mv_range,
        }
    end
    table.insert(screenfunc2, install_not_mv)
    local function install_has_mv()
        return {
            value = true,
            openfn = function(text, btn)
                if text then
                    has_mv_range = text
                    c_mana:SetLeft_Has_MV(has_mv_range)
                    btn.labeltext:SetString("抬手距离[开延迟]："..has_mv_range)
                end
            end,
            hover = "开延迟模时切换攻击模式的距离\n 该数值默认是0\n 你可以点击按钮修改",
            label = "抬手距离[开延迟]："..has_mv_range,
        }
    end
    table.insert(screenfunc2, install_has_mv)
    
    local rg_true = "攻击范围内再切装备\n注意：装备一次该武器后\n才会记录该武器的攻击范围"
    local rg_false = "尚未未启用此功能！\n 现在按下攻击键就会切装备"
    
    local function install_rgmode()
        return {
            value = rg_mode,
            fn = function(btn)
                rg_mode = not rg_mode
                btn.img_or:SetTexture("images/shroomcake_moreicons.xml", rg_mode and "right.tex" or "wrong.tex")
                btn.hovertext:SetString(rg_mode and rg_true or rg_false)
                c_mana:SetAttackRangeMode(rg_mode)
            end,
            hover = rg_mode and rg_true or rg_false,
            label = "攻击范围内再切武器",
        }
    end
    table.insert(screenfunc2, install_rgmode)

    local copy_true = "手动装备的物品将自动同步到移动栏\n 这样比较灵活"
    local copy_false = "手动装备的物品不会同步到移动栏\n 相当于锁移动栏"
    local function install_rcmode()
        return {
            value = copy_right,
            fn = function(btn)
                copy_right = not copy_right
                btn.img_or:SetTexture("images/shroomcake_moreicons.xml", copy_right and "right.tex" or "wrong.tex")
                btn.hovertext:SetString(copy_right and copy_true or copy_false)
                c_mana:SetRCMode(copy_right)
            end,
            hover = copy_right and copy_true or copy_false,
            label = "手动装备同步到移动栏",
        }
    end
    table.insert(screenfunc2, install_rcmode)

    local cp_true = "当前：启用\n 此功能在遇到模组装备时可能崩溃！\n 启用此功能会自动分配装备到对应栏位\n 启用此功能也将预判武器攻击范围"
    local cp_false = "当前：禁用\n 禁用此功能后，不再自动分配装备栏位\n 但是模组装备不再会引发崩溃了"

    local function install_cpmode()
       return {
            value = cp_mode,
            fn = function(btn)
                cp_mode = not cp_mode
                btn.img_or:SetTexture("images/shroomcake_moreicons.xml", cp_mode and "right.tex" or "wrong.tex")
                btn.hovertext:SetString(cp_mode and cp_true or cp_false)
                c_mana:SetCompatibleMode(cp_mode)
            end,
            hover = cp_mode and cp_true or cp_false,
            label = "预判模式",
       } 
    end
    table.insert(screenfunc2, install_cpmode)

    local init_light_prefab =  c_mana:GetBtnSlotData("light", "slot").prefab

    -- 进档将所有身上装备分配到行走栏(这一步是为了适配老档)
    t_util:Pairs(c_mana:GetSlotData(), function(_, eslot)
        if not ectrl or not ectrl.inst:IsValid() then return end
        local btn_slot = ectrl.line_walk[eslot]
        if not btn_slot then return end
        local equip = p_util:GetEquip(eslot)
        if not equip or not (equip.prefab==init_light_prefab) then
            btn_slot:install(equip or {})
        end
    end)
    -- 将手上武器添加到攻击范围
    local hands = p_util:GetEquip("hands")
    c_mana:SetAtkRange(hands and hands.prefab, p_util:GetAttackRange())
    -- 手里获得到装备时添加到攻击范围
    player:ListenForEvent("equip_withhx", function(player, meta)
        if meta.slot == "hands" then
            c_mana:SetAtkRange(meta.item and meta.item.prefab, p_util:GetAttackRange())
        end
    end)

    local function IsAEquip(item)
        return e_util:GetItemEquipSlot(item) and e_util:GetPercent(item)>0
    end

    local function Install_line_slot(cate, eslot, item)
        local btn_slot = ectrl["line_"..cate][eslot]
        if btn_slot then    -- 理论上不用判断，但谁知道呢
            local btn_prefab = c_mana:GetBtnSlotData(cate, eslot).prefab
            if cp_mode then
                local item_copy = e_util:ClonePrefab(item.prefab)
                local btn_copy = e_util:ClonePrefab(btn_prefab)
                -- 身上已有的容器优先级最高
                if table.contains(btn_copy.tags, "_container") then
                    return
                end
                local function compwalk()
                    return c_util:GreaterComn(item_copy, btn_copy,"equippable","walkspeedmult", 1)
                    and c_util:GreaterComn(item_copy, btn_copy,"equippable","dapperness") 
                    and c_util:GreaterComn(item_copy, btn_copy,"insulator","insulation") 
                    and c_util:GreaterTags(item_copy, btn_copy, {"dumbbell", "heavy", "backpack"})
                    and not e_util:IsLightSourceEquip(item)
                end
                local function compfight()
                    return c_util:GreaterComn(item_copy, btn_copy,"armor","absorb_percent") 
                    and c_util:GreaterComn(item_copy, btn_copy,"armor","basedefense") 
                    and c_util:GreaterComn(item_copy, btn_copy,"weapon","damage") 
                end
                if cate == "walk" then
                    if compwalk() then return btn_slot:install(item) end
                    if btn_prefab and btn_prefab~="null_huxi" then return end
                    if compfight() then return btn_slot:install(item) end
                elseif cate == "fight" then
                    if compfight() then return btn_slot:install(item) end
                    if btn_prefab and btn_prefab~="null_huxi" then return end
                    if compwalk() then return btn_slot:install(item) end
                end
                if table.contains(item_copy.tags, "_container") then
                    return btn_slot:install(item)
                end
            else
                if not btn_prefab or btn_prefab=="null_huxi"then
                    return btn_slot:install(item)
                end
            end
        end
    end

    player:ListenForEvent("itemget_withhx", function(player, meta)
        if not ectrl or not ectrl.inst:IsValid() then return end
        local item = meta.item
        local cont = meta.cont
        if cont and cont~=player and (not cont:HasTags({"inlimbo", "backpack"})) then
            return
        end
        local eslot = e_util:GetItemEquipSlot(item)
        local can_eat = p_util:GetInvAction(item, true, "eat")

        if eslot then
            -- 光源
            local light_data = c_mana:GetBtnSlotData("light", "slot")
            if (not light_data.prefab or light_data.fav==(item and item.prefab))
            and e_util:IsLightSourceEquip(item) then
                ectrl.about_light.slot:install(item)
            end
            -- 行走&攻击
            t_util:Pairs({"walk", "fight"}, function(_, cate)
                Install_line_slot(cate, eslot, item)
            end)
        end
        if can_eat then
            if not c_mana:GetBtnSlotData("eat", "slot").prefab then
                -- 不再考虑 挑食，糖豆，是否是料理的问题，因为反正一切都由玩家决定
                ectrl.about_eat.slot:install(item)
            end
        end
    end)

    
    -- 丢失物品的瞬间，还能拿到这个物品, 这个是bug?
    local function HasLeftPrefab(meta)
        return p_util:GetItemFromAll(meta.item.prefab, nil, function(ent) return ent ~= meta.item end, "hands")
    end

    player:ListenForEvent("itemlose_withhx", function(player, meta)
        if not ectrl or not ectrl.inst:IsValid() then return end
        local prefab = meta.item and meta.item.prefab
        if not prefab then return end

        -- 光源
        local light_prefab = c_mana:GetBtnSlotData("light", "slot").prefab
        if prefab == light_prefab then
            if not HasLeftPrefab(meta) then
                local light = p_util:GetItemFromAll(nil, nil, function(ent) return e_util:IsLightSourceEquip(ent) and e_util:GetPercent(ent)>0 end, "hands")
                ectrl.about_light.slot:install(light or {})
            end
        end

        -- 食物不做处理
        -- local eat_prefab = c_mana:GetBtnSlotData("eat", "slot").prefab
        -- if prefab == eat_prefab then
        --     if not HasLeftPrefab(meta) then
        --         local food = p_util:GetItemFromAll(nil, nil, function(item) return p_util:GetInvAction(item, true, "eat") end, "hands")
        --         ectrl.about_eat.slot:install(food or {})
        --     end
        -- end

        -- 装备
        local check_btns = {}
        local eslot = e_util:GetItemEquipSlot(meta.item) or meta.slot
        t_util:Pairs({"walk", "fight"}, function(_, cate)
            local btn_slot = ectrl["line_"..cate][eslot]
            if btn_slot then
                if c_mana:GetBtnSlotData(cate, eslot).prefab == prefab then
                    table.insert(check_btns, {
                        btn = btn_slot,
                        cate = cate,
                        slot = eslot
                    })
                end
            end
        end)
        if #check_btns ~= 0 then
            if not HasLeftPrefab(meta) then
                t_util:Pairs(check_btns, function(_, meta)
                    -- TODO:装备爆了后可以在这里完成自动部署
                    meta.btn:install({})
                end)
            end
        end

    end)
    player:ListenForEvent("indark_withhx", function(player, dark)
        inDark = dark
        if not ectrl or not ectrl.inst:IsValid() then return end
        if not c_mana:GetBtnTurnValue("light") then return end
        local prefab = c_mana:GetBtnSlotData("light", "slot").prefab
        if not prefab or prefab=="null_huxi" then return end
        local light = p_util:IsEquipped(prefab)
        if dark then
            -- 已经装备了耐久大于0且标记为光源的装备，就不管黑暗信号了
            if not light or e_util:GetPercent(light) <= 0 then
                light = p_util:GetItemFromAll(prefab, nil, IsAEquip, "hands")
                if light then p_util:Equip(light) else ectrl.about_light.slot:install({}) end
            end
        else
            -- 如果行走栏和光源栏都是这件装备，那么天亮就不卸载光源了
            if light then
                local eslot = e_util:GetItemEquipSlot(light)
                local walk_prefab = c_mana:GetBtnTurnValue("walk") and c_mana:GetBtnSlotData("walk", eslot).prefab
                if prefab ~= walk_prefab and p_util:CanTakeItem(light) then 
                    p_util:UnEquip(light) 
                end
            end
        end
    end)

    local function InHunger(player, meta)
        local hunger = player.replica and player.replica.hunger and player.replica.hunger:GetCurrent() <= starve_value
        if not hunger or p_util:IsInBusy() then return end
        if not ectrl or not ectrl.inst:IsValid() then return end
        if not c_mana:GetBtnTurnValue("eat") then return end
        local prefab = c_mana:GetBtnSlotData("eat", "slot").prefab
        if not prefab then return end
        local food = p_util:GetItemFromAll(prefab, nil, function(item)
            return p_util:GetInvAction(item, true, "eat")
        end, "hands")
        if food then p_util:Eat(food) 
            -- 禁止食物去除
        -- else 
            -- ectrl.about_eat.slot:install({}) 
        end
    end
    player:ListenForEvent("hungerdelta", InHunger)
    player:ListenForEvent("healthdelta", InHunger)


    -- 玩家的装备操作将复制到walk栏
    t_util:Pairs({"invslot", "equipslot"}, function(_, classname)
        local slotclass = require("widgets/"..classname)
        local _OnMouseButton = slotclass.OnMouseButton
        function slotclass:OnMouseButton(button, down, ...)
            if copy_right and down and button == GLOBAL.MOUSEBUTTON_RIGHT
                -- 某些玩家把检查或者丢弃键改了,那么这里就会有bug, 不过爆发了再说吧
                and not GLOBAL.TheInput:IsControlPressed(GLOBAL.CONTROL_FORCE_INSPECT)
                and not GLOBAL.TheInput:IsKeyDown(GLOBAL.KEY_SHIFT) then
                local item = self.tile and self.tile.item
                if item then
                    local eslot = e_util:GetItemEquipSlot(item)
                    if eslot then
                        if not ectrl or not ectrl.inst:IsValid() then return end
                        local btn_slot = ectrl.line_walk[eslot]
                        if btn_slot then
                            if p_util:GetInvAction(item, true, "equip") then
                                btn_slot:install(item)
                            -- 卸载不同步
                            -- elseif p_util:GetInvAction(item, true, "unequip") then
                            --     btn_slot:install({})
                            end
                        end
                    end
                end
            end
            return _OnMouseButton(self, button, down, ...)
        end
    end)
    


    local PC = player.components.playercontroller
    if not PC then return end
    
    local w_util = require "libs/worldutil"

    local function IsInDark()
        return inDark and w_util:IsDarkNight()
    end
    local attacktarget

    -- 攻击目标有对任意生物的仇恨即为战斗模式
    local function IsInFight()
        local iscreature = e_util:GetCombatTarget(attacktarget) and not attacktarget:HasTag("inlimbo") and not e_util:IsAnim("death", attacktarget)
        if iscreature then
            local dist = e_util:GetDist(attacktarget)
            return dist and dist < fight_range
        end
    end

    local function SyncSlot(cate, eslot, equip)
        local btn_prefab = c_mana:GetBtnSlotData(cate, eslot).prefab
        -- 卸载的条件：有装备且格子未满
        if not btn_prefab or btn_prefab == "null_huxi" then
            if not equip or not p_util:CanTakeItem(equip) then 
                return 
            end
            p_util:UnEquip(equip)
        -- 装备的条件：正在装的不是walk且有这件装备
        else
            if equip and equip.prefab == btn_prefab then
                return
            end
            local item = p_util:GetItemFromAll(btn_prefab, nil, function(ent)
                return e_util:GetItemEquipSlot(ent) and p_util:GetInvAction(ent, true, "equip")
            end, "hands")
            if item then
                p_util:Equip(item)
                -- 能否这样修复？
                if cate == "fight" then
                    p_util:Click(attacktarget)
                end
            else
                -- 错误的装备如何处理
                if not ectrl or not ectrl.inst:IsValid() then return end
                local btn = ectrl["line_"..cate][eslot]
                if btn then 
                    if cate == "walk" then
                        btn:install({}) 
                    else
                        item = p_util:GetItemFromAll(nil, nil, function(ent)
                            return e_util:GetItemEquipSlot(ent)==eslot and p_util:GetInvAction(ent, true, {"equip", "unequip"})
                        end, "hands")
                        btn:install(item or {}) 
                    end
                end
            end
        end
    end

    -- walk模式
    local function StartWalk()
        if not c_mana:GetBtnTurnValue("walk") or not p_util:IsInvEnabled() then
            return
        end
        local light_prefab = c_mana:GetBtnSlotData("light", "slot").prefab
        local has_heavy = t_util:GetElement(c_mana:GetSlotData(), function(_, eslot)
            local equip = p_util:GetEquip(eslot)
            return equip and equip:HasTag("heavy")
        end)
        if has_heavy then
            return
        end
        t_util:Pairs(c_mana:GetSlotData(), function(_, eslot)
            -- 忽略此栏
            if not c_mana:GetBtnSlotData("walk", eslot).value then
                return
            end
            local equip = p_util:GetEquip(eslot)
            -- print(eslot, c_mana:GetBtnSlotData("walk", eslot).value,  c_mana:GetBtnSlotData("walk", eslot).prefab, equip)
            -- 光源优先级最高
            if light_prefab and light_prefab ~= "null_huxi" and IsInDark() 
            and equip and equip.prefab == light_prefab then
                return 
            end
            -- 战斗模式下，不切换除了手部的装备
            if IsInFight() and eslot ~= "hands" then
                return
            end
            SyncSlot("walk", eslot, equip)
        end)
    end
    local function SwitchFight()
        -- 战斗的话就不管光源啦，让玩家自己处理吧
        t_util:Pairs(c_mana:GetSlotData(), function(_, eslot)
            -- 忽略此栏
            if not c_mana:GetBtnSlotData("fight", eslot).value then
                return
            end
            SyncSlot("fight", eslot, p_util:GetEquip(eslot))
        end)
    end

    local function StartFight()
        -- 攻击目标是建筑之类的不切甲吧
        if not e_util:IsValid(attacktarget) or 
        e_util:IsAnim("death", attacktarget) or
        not (attacktarget.replica and attacktarget.replica.combat) or
        not p_util:IsInvEnabled()
        then
            return
        end

        if attacktarget:HasOneOfTags({"butterfly", "stalkerminion"}) or attacktarget.prefab == "shadowchanneler" then
            return
        end

        
        if not c_mana:GetBtnTurnValue("fight") then
            return
        end

        -- 攻击范围内再切甲
        if rg_mode then
            local data = c_mana:GetBtnSlotData("fight", "hands")
            local prefab
            if data.value and data.prefab then
                prefab = data.prefab
            else
                local hands = p_util:GetEquip("hands")
                prefab = hands and hands.prefab
            end
            local atkrange = c_mana:GetAtkRange(prefab) + attacktarget:GetPhysicsRadius(0) 
            local dist = e_util:GetDist(attacktarget)

            -- 提前切武器
            -- 客机关延迟模式需要这个值
            atkrange = atkrange + (PC and PC.locomotor and has_mv_range or not_mv_range)
            if dist and dist <= atkrange  then
                SwitchFight()
            end
        else
            SwitchFight()
        end
    end

    -- 通用点击
    -- local _OnLeftClick = PC.OnLeftClick
    -- function PC:OnLeftClick(down, ...)
    --     if down and not GLOBAL.TheInput:GetHUDEntityUnderMouse() and not PC:GetLeftMouseAction() then
    --         StartWalk()
    --         self.inst:DoTaskInTime(GLOBAL.FRAMES, function()
    --             _OnLeftClick(self, down)
    --         end)
    --     end
    --     return _OnLeftClick(self, down, ...)
    -- end

    local _DoDirectWalking = PC.DoDirectWalking
    function PC:DoDirectWalking(...)
        if self.directwalking then
            StartWalk()
        elseif GLOBAL.TheInput:IsControlPressed(GLOBAL.CONTROL_ATTACK) then
            StartFight()
        end
        return _DoDirectWalking(self, ...)
    end

    -- 开始索敌触发，持续攻击时不触发
    local _GetAttackTarget = PC.GetAttackTarget
    function PC:GetAttackTarget(...)
        local retarget = _GetAttackTarget(self, ...)
        attacktarget = retarget or attacktarget
        return retarget
    end


    local ignorestr = {"SOUL", "FREESOUL"} 
    local function ValidateAction(self)
        local act = self:GetRightMouseAction()
        return act
        and act.action == GLOBAL.ACTIONS.BLINK
        and not table.contains(ignorestr, act.action.strfn(act))
        and not self.placer
    end
    -- 双击闪现
    local count_tele = 2
    local _OnRightClick = PC.OnRightClick
    local function flush_action_str(num)
        count_tele = num and count_tele + num or 2
        GLOBAL.STRINGS.ACTIONS.BLINK.GENERIC = string.format(
            string_tele .. " (%s)",
            count_tele
        )
    end
    if double_click then
        flush_action_str()
    end
    local function install_dbclick()
        return {
            value = double_click,
            fn = function(btn)
                double_click = not double_click
                btn.img_or:SetTexture("images/shroomcake_moreicons.xml", double_click and "right.tex" or "wrong.tex")
                btn.hovertext:SetString(double_click and "懒人手杖双击才能传送:开启" or "懒人手杖双击才能传送：关闭")
                c_mana:SetDBClick(double_click)
                if not double_click then
                    GLOBAL.STRINGS.ACTIONS.BLINK.GENERIC = string_tele
                else
                    flush_action_str()
                end
            end,
            hover = double_click and "懒人手杖双击才能传送:开启" or "懒人手杖双击才能传送：关闭",
            label = "双击闪现",
        }
    end
    table.insert(screenfunc2, install_dbclick)

    function PC:OnRightClick(down)
        if down and ValidateAction(self) and double_click then
            if double_click then
                if count_tele > 0 then
                    flush_action_str(-1)
                    self.inst:DoTaskInTime(0.5, function()
                        flush_action_str()
                    end)
                end
                if count_tele > 0 then
                    return
                end
            end
        end

        _OnRightClick(self, down)
    end
end

AddPlayerActivatedFunc(function(player)
    -- 防止进档重新排序
    if not string_tele then
        string_tele = GLOBAL.STRINGS.ACTIONS and GLOBAL.STRINGS.ACTIONS.BLINK and GLOBAL.STRINGS.ACTIONS.BLINK.GENERIC
        string_tele = type(string_tele) == "string" and string_tele or "传送"
    end
    player:DoTaskInTime(1, EquipmentControl)
end)



-------------------------加载-------------------
local screen
local function Fn()
    local screen_name = TheFrontEnd:GetActiveScreen().name
    screen_name = TheFrontEnd:GetActiveScreen().name
    if "EctrlScreen" == screen_name then
        TheFrontEnd:PopScreen(screen)
    else
        local screendata = {}
        t_util:Pairs(t_util:MergeMap(screenfunc1, screenfunc2), function(_, func)
            if type(func) == "table" then
                table.insert(screendata, func)
            elseif type(func) == "function" then
                table.insert(screendata, func())
            end
        end)
        screen = require("screens/ectrlscreen")(screendata)
        TheFrontEnd:PushScreen(screen)
    end
end
if GetModConfigData("sw_equipcontrol") == "biubiu" then
DEAR_BTNS:AddDearBtn(GLOBAL.GetScrapbookIconAtlas("icon_health.tex"), "icon_health.tex", "装备大师", "这里进行更多设置", true, Fn)
end
AddBindBtn("sw_equipcontrol", Fn)